package com.zhihuichongcheng.application.ui.main.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.smartlib.cmnObject.recycleView.OnItemOnclick;
import com.zhihuichongcheng.application.R;
import com.zhihuichongcheng.application.bean.cricle.CricleCountBean;
import com.zhihuichongcheng.application.glide.GlideCircleTransform;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 3water on 2016/10/31.
 */

public class CricleCountAdapter extends RecyclerView.Adapter<CricleCountAdapter.ViewHold> {
    private Context mContext;
    private OnItemOnclick<CricleCountBean> onItemOnclick;
    private List<CricleCountBean> mListData = new ArrayList<>();

    public CricleCountAdapter(Context context) {
        this.mContext = context;
    }

    public void setOnItemOnclick(OnItemOnclick<CricleCountBean> onItemOnclick) {
        this.onItemOnclick = onItemOnclick;
    }

    public void setData(List<CricleCountBean> list) {
        this.mListData = list;
    }

    @Override
    public ViewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.listadapter_cricle_count, null);
        return new ViewHold(view);
    }

    @Override
    public void onBindViewHolder(ViewHold holder, final int position) {
        final CricleCountBean bean = mListData.get(position);
        holder.mTvName.setText(bean.getCategoryName());
        holder.mTvCount.setText("已经产生了" + bean.getCount() + "条数据");
        Glide.with(mContext).load(bean.getCategoryLogo()).placeholder(R.drawable.ic_cricle_defalut).transform(new GlideCircleTransform(mContext)).into(holder.mImAvatar);
        int unReadcomment = bean.getUnReadComment();
        if (unReadcomment > 0) {
            holder.mTvNuread.setVisibility(View.VISIBLE);
            holder.mTvNuread.setText(unReadcomment + "");
        } else {
            holder.mTvNuread.setVisibility(View.GONE);

        }

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemOnclick != null) {
                    onItemOnclick.onClick(bean, position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mListData.size();
    }

    class ViewHold extends RecyclerView.ViewHolder {
        private ImageView mImAvatar;
        private View view;
        private TextView mTvName, mTvNuread;
        private TextView mTvCount;

        public ViewHold(View itemView) {
            super(itemView);
            view = itemView;
            mImAvatar = (ImageView) itemView.findViewById(R.id.im_avatar);
            mTvName = (TextView) itemView.findViewById(R.id.tv_title);
            mTvCount = (TextView) itemView.findViewById(R.id.tv_num);
            mTvNuread = (TextView) itemView.findViewById(R.id.tv_unread);
        }
    }
}
